import requests
from concurrent.futures import ThreadPoolExecutor

# 子域名前缀列表
prefixes = [
    "api.", "subapi.", "mobile.", "cms.", "subweb.",
    "app.", "cms2.", "appapi."
]

# 设置主域名（可根据需要改成读取文件或用户输入）
main_domain = "bohaiyinshua.com"

# 构造完整子域名列表
def build_subdomains(domain: str):
    return [f"{prefix}{domain}" for prefix in prefixes]

# 检查 URL 是否畅通（尝试 https 和 http）
def check_subdomain(subdomain: str):
    for scheme in ["https://", "https://"]:
        url = f"{scheme}{subdomain}"
        try:
            response = requests.get(url, timeout=3)
            return f"[✅] {url} - {response.status_code}"
        except requests.RequestException:
            continue
    return f"[❌] {subdomain} - 无法访问"

# 主程序
def main():
    subdomains = build_subdomains(main_domain)
    print(f"开始检测域名：{main_domain} 的子域连通性...\n")

    with ThreadPoolExecutor(max_workers=10) as executor:
        results = executor.map(check_subdomain, subdomains)

    for result in results:
        print(result)

if __name__ == "__main__":
    main()
